package com.edu.exam.entity.assessment.scheme;

import com.edu.exam.enums.assessment.AssessmentMethod;
import com.edu.exam.enums.assessment.AssessmentTiming;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 考核项目实体类
 * 所属模块：B-04 考核方案管理模块
 * 对应数据库表：assessment_scheme_item
 *
 * <p>考核项目是考核方案中的具体考核项目，定义考核方式、权重和时机。
 * 支持权重验证功能，确保权重分配的合理性。与考核标准关联，定义项目的评价标准。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
@EntityListeners(AuditingEntityListener.class)
public class AssessmentSchemeItem {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 关联方案ID
     */
    @Column(name = "scheme_id", nullable = false)
    private Long schemeId;

    /**
     * 项目名称
     */
    @Column(name = "name", nullable = false, length = 200)
    private String name;

    /**
     * 项目描述
     */
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    /**
     * 考核方式
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "method", nullable = false, length = 50)
    private AssessmentMethod method;

    /**
     * 权重
     */
    @Column(name = "weight", nullable = false, precision = 5, scale = 2)
    private BigDecimal weight;

    /**
     * 最高分数
     */
    @Column(name = "max_score", nullable = false)
    private Integer maxScore;

    /**
     * 考核时机
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "timing", nullable = false, length = 20)
    private AssessmentTiming timing;

    /**
     * 计划标识
     */
    @Column(name = "plan_flag", nullable = false)
    private Boolean planFlag = false;

    /**
     * 考核时长（分钟）
     */
    @Column(name = "duration")
    private Integer duration;

    /**
     * 考核地点
     */
    @Column(name = "location", length = 200)
    private String location;

    /**
     * 考核要求
     */
    @Column(name = "requirements", columnDefinition = "TEXT")
    private String requirements;

    /**
     * 考核材料
     */
    @Column(name = "materials", columnDefinition = "TEXT")
    private String materials;

    /**
     * 备注
     */
    @Column(name = "remarks", length = 500)
    private String remarks;

    /**
     * 排序顺序
     */
    @Column(name = "sort_order")
    private Integer sortOrder = 0;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 是否删除
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "deleted_time")
    private LocalDateTime deletedTime;

    /**
     * 删除人ID
     */
    @Column(name = "deleted_by")
    private Long deletedBy;

    // ===== 关联对象 =====

    /**
     * 所属考核方案
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "scheme_id", insertable = false, updatable = false)
    private AssessmentSchemeManagement scheme;

    /**
     * 关联的考核标准列表
     */
    @OneToMany(mappedBy = "item", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<AssessmentSchemeStandard> standards;

    // ===== 业务方法 =====

}

    